package com.ctshk.rpc.order.tour.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.order.tour.dto.SeriesOrderTouristRefundDetailListDTO;
import com.ctshk.rpc.order.tour.dto.SeriesOrderTouristRefundDetailListTripDTO;
import com.ctshk.rpc.order.tour.entity.SeriesOrderTouristRefundDetail;
import com.ctshk.rpc.order.tour.mapper.SeriesOrderTouristRefundDetailMapper;
import com.ctshk.rpc.order.tour.req.SeriesOrderTouristRefundDetailListReq;
import com.ctshk.rpc.order.tour.req.SeriesOrderTouristRefundDetailListTripReq;
import com.ctshk.rpc.order.tour.service.ISeriesOrderTouristRefundDetailService;
import com.ctshk.rpc.system.dto.UserDTO;
import com.ctshk.rpc.system.service.ISysUserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 系列团退款明细 服务实现类
 * </p>
 *
 * @author 谭响
 * @since 2021-01-28
 */
@DubboService
public class SeriesOrderTouristRefundDetailServiceImpl extends ServiceImpl<SeriesOrderTouristRefundDetailMapper, SeriesOrderTouristRefundDetail> implements ISeriesOrderTouristRefundDetailService {


    @Autowired
    private SeriesOrderTouristRefundDetailMapper seriesOrderTouristRefundDetailMapper;

    @DubboReference
    private ISysUserService iSysUserService;

    /**
     * 列表
     */
    @Override
    public PageResponse<SeriesOrderTouristRefundDetailListDTO> list(SeriesOrderTouristRefundDetailListReq req) {
        IPage<SeriesOrderTouristRefundDetailListReq> pageParam = new Page<>(req.getPageNo(), req.getPageSize());
        IPage<SeriesOrderTouristRefundDetailListDTO> pageResult = seriesOrderTouristRefundDetailMapper.selectListBySelective(pageParam, req);
        for (SeriesOrderTouristRefundDetailListDTO record : pageResult.getRecords()) {
            if(record.getCreateId() == null) {
                continue;
            }
            if (record.getCreateId() != null){
                UserDTO userDTO = iSysUserService.queryCacheUser(record.getCreateId());
                if (userDTO != null){
                    record.setCreateName(userDTO.getFullName());
                    record.setCreateDept(userDTO.getDept());
                }
            }
        }
        PageResponse<SeriesOrderTouristRefundDetailListDTO> pageResponse = new PageResponse<>(pageResult.getRecords(),
                pageResult.getCurrent() == 1,
                pageResult.getTotal() <= (pageResult.getCurrent() * pageResult.getSize()),
                pageResult.getTotal(), pageResult.getCurrent(),
                pageResult.getSize());
        return pageResponse;
    }

    /**
     * 列表团期
     */
    @Override
    public PageResponse<SeriesOrderTouristRefundDetailListTripDTO> listTrip(SeriesOrderTouristRefundDetailListTripReq req) {
        IPage<SeriesOrderTouristRefundDetailListTripReq> pageParam = new Page<>(req.getPageNo(), req.getPageSize());
        IPage<SeriesOrderTouristRefundDetailListTripDTO> pageResult = seriesOrderTouristRefundDetailMapper.selectListTripBySelective(pageParam, req);
        PageResponse<SeriesOrderTouristRefundDetailListTripDTO> pageResponse = new PageResponse<>(pageResult.getRecords(),
                pageResult.getCurrent() == 1,
                pageResult.getTotal() <= (pageResult.getCurrent() * pageResult.getSize()),
                pageResult.getTotal(), pageResult.getCurrent(),
                pageResult.getSize());
        return pageResponse;
    }

}
